﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VideoCache.Server.Model;

namespace VideoCache.Server.BLL
{
    public partial class DictionaryBLL
    {
        public static DictionaryInfo GetDictionary(int id)
        {
            if (CacheBLL.Contains("Dictionary"))
            {
                List<DictionaryInfo> list = CacheBLL.GetCache<List<DictionaryInfo>>("Dictionary");

                if (list.Exists(p => p.Id == id))
                {
                    return list.Find(p => p.Id == id);
                }
                else
                {
                    DictionaryInfo info = DictionaryBLL.Find(id);
                    if (info != null)
                    {
                        list.Add(info);
                    }
                    return info;
                }
            }
            else
            {
                CacheBLL.CreateCache("Dictionary", DictionaryBLL.FindAll(null, null));
            }

            return null;
        }
    }
}